<template>
	<view class="Billing">
		<nav-bar title="订单开单"></nav-bar>
		<scroll-view :style="{ height: scrollHeight }" :scroll-y="true">
			<common-form ref="userFormRef" v-model="formData" formTitle="客户信息" :formConfig="customerConfig"
				@phoneNumberBlur="phoneNumberBlur" />
			<common-form ref="projectFormRef" v-model="projectFormData" formTitle="项目信息" :formConfig="projectConfig"
				@projectIdChange="projectIdChange" @goodsChange="goodsChange" @chooseTimeChange="chooseTimeChange"
				@typeIdChange='typeIdChange' @technicianIdChange="technicianIdChange">
				<view slot="bottomBox">
					<view class="btn-box">
						<view class="add-btn" @click="clickAddProject">
							添加服务项目
						</view>
					</view>
					<view v-if="zyOrderItemList && zyOrderItemList.length">
						<view class="project-list" v-for="(item, index) in zyOrderItemList" :key="index">
							<view class="common-item">
								<view class="item">{{ item.itemName }}</view>
								<view class="item">
									{{ item.zyOrderProductList ? item.zyOrderProductList[0].productName : '' }}
								</view>
							</view>
							<view class="common-item">
								<view class="item">{{ item.technicianName }}</view>
								<view class="item">{{ item.subscribeStartTime }}</view>
							</view>
							<view class="delete-box">
								<view class="delete-btn" @click="clickDeleteProject(item,index)">删除</view>
							</view>
						</view>
					</view>
				</view>
			</common-form>
			<common-form v-model="formData" formTitle="包间" :formConfig="roomConfig" @needRoomChange="needRoomChange"
				@compartmentIdChange="compartmentIdChange" />
			<view class="fee-detail">
				<view class="fee-title">费用明细</view>
				<view class="fee-item" v-for="(item, index) in accountConfig" :key="index">
					<view class="fee-label">{{ item.label }}</view>
					<view class="fee-value">{{ feeKeys(item.value) || '--' }}元</view>
				</view>
				<view class="btn-box">
					<view class="confirm-btn" @click="clickSubmit('payAfter')">稍后支付</view>
					<view class="confirm-btn" @click="clickSubmit('payNow')">立即支付</view>
				</view>
			</view>
		</scroll-view>
		<you-popup :popupVisible="payInfoDialog" :showTitle="false" :showBtn="false"
			@popupClose="payInfoDialog = false">
			<template #popupContent>
				<view class="pay-info-box">
					<view class="pay-info-item" v-for="(item, index) in payInfoConfig" :key="index">
						<view :class="['item-label', item.select ? 'item-select-label' : '']">{{ item.label }}：</view>
						<view class="item-select" v-if="item.select">
							<uni-data-select class="select" v-model="payInfoData[item.key]"
								:localdata="payInfoOptions[item.key]"
								@change="selectChange($event, item)"></uni-data-select>
						</view>
						<view class="item-value" v-else>
							{{ item.money ? feeKeys(item.key) || '--' : payInfoData[item.key] }}{{ item.suffix }}
						</view>
					</view>
					<view class="input-box" v-if="payInfoData.paymentType === '8'">
						<uni-easyinput v-model="payInfoData.groupPurchaseId" placeholder="请输入券码"></uni-easyinput>
						<uni-easyinput v-model="payInfoData.groupPurchaseMoney" placeholder="请输入实收金额"></uni-easyinput>
					</view>
					<view class="pay-btn" @click="clickSubmitPay">确认</view>
				</view>
			</template>
		</you-popup>
		<you-popup :popupVisible="deleteDialog" :showBtn="false" popupTitle="删除项目" @popupClose="deleteDialog = false">
			<template #popupContent>
				<view class="delete-box">
					<view class="delete-text">是否确认删除该项目？</view>
					<view class="delete-btn">
						<view class="btn-item" @click="clickConfirmDelete">是</view>
						<view class="btn-item cancel-item" @click="deleteDialog=false">否</view>
					</view>
				</view>
			</template>
		</you-popup>
		<you-popup :popupVisible="payDialog" :showTitle="false" :showBtn="false" @popupClose="payDialog = false">
			<template #popupContent>
				<view class="pay-box">
					<view class="pay-item">
						支付方式：{{ payTypeConfig[payInfoData.paymentType] }}
					</view>
					<view class="pay-item">
						实付金额：{{ actuallyMoney }}元
					</view>
					<view class="confirm-pay-btn" @click="clickSurePay">确定收款</view>
				</view>
			</template>
		</you-popup>
	</view>
</template>

<script>
	import YouPopup from "@/components/you-popup/index1.vue"
	import NavBar from "@/components/nav-bar"
	import commonForm from './commonForm.vue'
	import {
		CUSTOMER_CONFIG,
		PROJECT_CONFIG,
		ROOM_CONFIG
	} from './formConfig/orderConfig'
	import {
		fetchCustomInfo,
		fetchProjectList,
		fetchTechnicianList,
		fetchGoodsList,
		fetchRoomsList,
		fetchCouponList,
		fetchCouponDiscount,
		addOrder,
		orderPay,
		listTypeByStore
	} from '@/api/order'
	export default {
		name: "OrderBilling",
		components: {
			NavBar,
			YouPopup,
			commonForm
		},
		data() {
			return {
				scrollHeight: '',
				customerConfig: [],
				projectConfig: [],
				roomConfig: [],
				accountConfig: [{
						label: '项目金额',
						value: 'allProjectMoney'
					},
					{
						label: '附加商品金额',
						value: 'allGoodsMoney'
					},
					{
						label: '包间费用',
						value: 'roomMoney'
					},
					{
						label: '总金额',
						value: 'totalMoney'
					}
				],
				formData: {},
				projectFormData: {}, // 项目的表单数据
				nowProjectMoney: 0, // 当前展示的项目金额
				nowGoodsMoney: 0, // 当前展示的附加商品金额
				roomMoney: 0, // 包间费用
				zyOrderItemList: [],
				chooseProject: {}, // 当前选择的项目
				chooseRoom: {}, // 当前选择的包间
				chooseTechnician: {}, // 当前选择的技师
				chooseGoods: {}, // 当前选择的附加商品
				payInfoDialog: false,
				payInfoConfig: [{
						label: '客户手机号',
						key: 'phoneNumber'
					},
					{
						label: '客户姓名',
						key: 'userName'
					},
					{
						label: '余额',
						key: 'valueMoney',
						suffix: '元'
					},
					{
						label: '会员权益',
						key: 'memberFlag'
					},
					{
						label: '订单金额',
						key: 'orderAmount',
						suffix: '元'
					},
					{
						label: '优惠方式',
						key: 'discountType',
						select: true
					},
					{
						label: '优惠券',
						key: 'itemZyUserCouponId',
						select: true
					},
					{
						label: '优惠金额',
						key: 'discountsMoney',
						money: true,
						suffix: '元'
					},
					{
						label: '实付金额',
						key: 'actuallyMoney',
						money: true,
						suffix: '元'
					},
					{
						label: '支付方式',
						key: 'paymentType',
						select: true
					}
				],
				payInfoOptions: {
					discountType: [{
							text: '会员权益',
							value: 'member'
						},
						{
							text: '储值卡',
							value: 'storeCard'
						},
					],
					itemZyUserCouponId: [],
					paymentType: [
						// { text: '微信', value: '1' },
						// { text: '支付宝', value: '2' },
						{
							text: '现金',
							value: '3'
						},
						// { text: '银行卡', value: '4' },
						{
							text: '余额',
							value: '5'
						},
						// { text: '其他', value: '6' },
						{
							text: '扫码支付',
							value: '7'
						},
						{
							text: '团购券',
							value: '8'
						}
					]
				},
				payInfoData: {},
				deleteDialog: false,
				deleteItem: '', // 要删除的项目信息
				payDialog: false,
				payTypeConfig: {
					// '1': '微信',
					// '2': '支付宝',
					'3': '现金',
					// '4': '银行卡',
					'5': '余额',
					// '6': '其他',
					'7': '扫码支付',
					'8': '团购券'
				},
				orderId: '',
				couponDiscount: 0,
				chooseCoupon: null,
				payMethod: '',
				SubmitParams: {},
				payCode: ''
			}
		},
		computed: {
			allProjectMoney() { // 项目金额
				return this.nowProjectMoney
			},
			allGoodsMoney() { // 附加商品金额
				return this.nowGoodsMoney
			},
			totalMoney() { // 订单总金额
				// console.log(this.allProjectMoney, 'this.allProjectMoney');
				// console.log(this.allGoodsMoney, 'this.allGoodsMoney');
				// console.log(this.roomMoney, 'this.roomMoney');
				const projectAccount = this.$methods.numberAdd(this.allProjectMoney, this.allGoodsMoney)
				return this.$methods.numberAdd(projectAccount, this.roomMoney)
			},
			discountsMoney() { // 优惠金额
				return this.couponDiscount
			},
			actuallyMoney() { // 实付金额
				return this.$methods.numberSub(this.totalMoney, this.discountsMoney)
			}
		},
		onLoad() {
			this.heightConfig = this.$store.getters.heightData
			this.scrollHeight = this.heightConfig.noTabMainHeight - 15 + 'px'
			this.customerConfig = uni.$u.deepClone(CUSTOMER_CONFIG)
			this.projectConfig = uni.$u.deepClone(PROJECT_CONFIG)
			console.log(uni.$u.deepClone(PROJECT_CONFIG), 'uni.$u.deepClone(PROJECT_CONFIG)');
			this.roomConfig = uni.$u.deepClone(ROOM_CONFIG)
			this.getlistType()
			this.getGoodsList()
		},
		onShow() {
			const now = new Date();
			const oneMinute = 60 * 1024; // 一分钟的毫秒数
			const newDate = new Date(now.getTime() + oneMinute);
			this.projectFormData.chooseTime = newDate.getTime();
			this.getTechnicianList()
		},
		methods: {
			feeKeys(value) {
				return this[value]
			},
			// 获取客户的信息
			phoneNumberBlur(value) {
				if (!value) return
				const params = {
					phoneNumber: value,
					regionId: uni.getStorageSync('technician').belongAreaId,
					storeId: uni.getStorageSync('technician').belongStoreId
				}
				fetchCustomInfo(params).then(res => {
					if (res.code !== 200) return
					this.formData = {
						...this.formData,
						userName: res.data.userName,
						valueMoney: res.data.valueMoney,
						memberFlag: res.data.memberFlag ? '1' : '2'
					}
					if (res.data.memberFlag && res.data.valueFlag) {
						this.payInfoOptions.discountType = [{
								text: '会员权益',
								value: 'member'
							},
							{
								text: '储值卡',
								value: 'storeCard'
							}
						]
					} else {
						if (res.data.memberFlag) {
							this.payInfoOptions.discountType = [{
								text: '会员权益',
								value: 'member'
							}]
						}
						if (res.data.valueFlag) {
							this.payInfoOptions.discountType = [{
								text: '储值卡',
								value: 'storeCard'
							}]
						}
						if (!res.data.memberFlag && !res.data.valueFlag) {
							this.payInfoOptions.discountType = []
						}
					}
				})
			},
			//获取项目类型下拉
			getlistType() {
				listTypeByStore({
					storeId: uni.getStorageSync('technician').belongStoreId
				}).then(res => {
					const projectFormConfig = uni.$u.deepClone(this.projectConfig)
					projectFormConfig.forEach(item => {
						if (item.key === 'typeId') {
							item.options = res.data.map(rItem => {
								return {
									...rItem,
									text: rItem.typeName,
									value: rItem.id
								}
							})
						}
					})
					this.projectConfig = uni.$u.deepClone(projectFormConfig)
				})
			},
			// 获取服务项目下拉
			getProjectList(typeV) {
				const params = {
					storeId: uni.getStorageSync('technician').belongStoreId,
					typeId: typeV
				}
				fetchProjectList(params).then(res => {
					if (res.code !== 200) return
					const projectFormConfig = uni.$u.deepClone(this.projectConfig)
					projectFormConfig.forEach(item => {
						if (item.key === 'projectId') {
							item.options = res.rows.map(rItem => {
								return {
									...rItem,
									text: rItem.itemName,
									value: rItem.itemId
								}
							})
						}
					})
					this.projectConfig = uni.$u.deepClone(projectFormConfig)
				})
			},
			typeIdChange(value, item) {
				this.getProjectList(value)
			},
			projectIdChange(value, item) {
				this.projectConfig.forEach(item => {
					if (item.key === 'chooseTime') {
						item.isDisabled = !value
					}
				})
				this.chooseProject = item.options.find(oItem => oItem.value === value)
				this.getTechnicianList()
			},
			chooseTimeChange() {
				this.getTechnicianList()
			},
			formatDate(timestamp) {
				const date = new Date(timestamp);
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0');
				const day = String(date.getDate()).padStart(2, '0');
				const hours = String(date.getHours()).padStart(2, '0');
				const minutes = String(date.getMinutes()).padStart(2, '0');
				const seconds = String(date.getSeconds()).padStart(2, '0');
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
			},
			// 获取技师下拉
			getTechnicianList() {
				const projectFormDataTime = this.formatDate(this.projectFormData.chooseTime)
				const params = {
					itemStoreId: this.chooseProject.id,
					date: projectFormDataTime.split(' ')[0],
					time: projectFormDataTime.split(' ')[1]
				}
				fetchTechnicianList(params).then(res => {
					if (res.code !== 200) return
					const projectFormConfig = uni.$u.deepClone(this.projectConfig)
					projectFormConfig.forEach(item => {
						if (item.key === 'technicianId') {
							item.options = res.rows.map(rItem => {
								let minute = rItem.serviceEndTime ?
									Math.round(
										(Number(rItem.serviceEndTime) -
											Date.parse(projectFormDataTime)) /
										1000 /
										60
									) :
									0;
								console.log(minute, 'minute');
								if (minute < 60) {
									minute = `${minute} 分钟`;
								} else if (minute < 1440) {
									const hours = Math.floor(minute / 60);
									const remainingMinutes = minute % 60;
									minute = `${hours}小时${remainingMinutes}分钟`;
								} else {
									const days = Math.floor(minute / 1440);
									const remainingMinutes = minute % 1440;
									const hours = Math.floor(remainingMinutes / 60);
									const finalMinutes = remainingMinutes % 60;
									minute = `${days}天${hours}小时${finalMinutes}分钟`;
								}
								let minuteNum = rItem.serviceEndTime ?
									Math.round(
										(Number(rItem.serviceEndTime) -
											Date.parse(projectFormDataTime)) /
										1000 /
										60
									) :
									0;

								return {
									...rItem,
									text: rItem.status == '休息' ?
										`${rItem.jobNumber}号${rItem.name}/休息中` :
										`${rItem.jobNumber}号${rItem.name}/需等待${minute}`,
									value: rItem.id,
									minute: minuteNum,
									disable: rItem.status == '休息' ? true : false
								}
							})
						}
					})
					this.projectConfig = uni.$u.deepClone(projectFormConfig)
					console.log(this.projectConfig, 'this.projectConfig');
				})
			},
			technicianIdChange(value, item) {
				this.chooseTechnician = item.options.find(oItem => oItem.value === value)
			},
			// 获取附加商品列表
			getGoodsList() {
				const params = {
					storeId: uni.getStorageSync('technician').belongStoreId
				}
				fetchGoodsList(params).then(res => {
					if (res.code !== 200) return
					const projectFormConfig = uni.$u.deepClone(this.projectConfig)
					projectFormConfig.forEach(item => {
						if (item.key === 'goods') {
							item.options = res.data.map(rItem => {
								return {
									...rItem,
									text: rItem.productName,
									value: rItem.id
								}
							})
						}
					})
					this.projectConfig = uni.$u.deepClone(projectFormConfig)
				})
			},
			goodsChange(value, item) {
				this.chooseGoods = item.options.find(oItem => oItem.value === value)
			},
			needRoomChange($event) {
				this.roomConfig.forEach(item => {
					if (item.key === 'compartmentId') {
						item.hiddenItem = $event === '2'
					}
				})
				if ($event === '2') {
					this.formData.compartmentId = null
					this.chooseRoom = {}
					this.roomMoney = 0
				}
			},
			//获取床位数
			getBedNumber() {
				const number = this.zyOrderItemList.reduce((acc, current) => {
					const x = acc.find(item => item.technicianId === current.technicianId);
					if (!x) {
						acc.push(current);
					}
					return acc;
				}, []);
				console.log(number, 'technicianId');
				return number.length
			},
			// 获取包间列表
			getRoomsList() {
				const params = {
					storeId: uni.getStorageSync('technician').belongStoreId,
					roomType: 1,
					bedNumber: this.getBedNumber()
				}
				fetchRoomsList(params).then(res => {
					if (res.code !== 200) return
					const roomFormConfig = uni.$u.deepClone(this.roomConfig)
					roomFormConfig.forEach(item => {
						if (item.key === 'compartmentId') {
							item.options = res.rows.map(rItem => {
								return {
									...rItem,
									text: rItem.compartmentName,
									value: rItem.id
								}
							})
						}
					})
					this.roomConfig = uni.$u.deepClone(roomFormConfig)
				})
			},
			compartmentIdChange(value, item) {
				if (!value) this.roomMoney = 0
				item.options.forEach(oItem => {
					if (oItem.value === value) {
						this.chooseRoom = oItem
						this.roomMoney = oItem.privateRoomPrice
					}
				})
			},
			//计算分钟
			addMinutes(time, minutes) {
				const newTime = time.split(' ')[1]
				const newdata = time.split(' ')[0]
				const [hours, mins, secs] = newTime.split(":").map(Number);
				const totalMinutes = parseInt(hours * 60 + mins + minutes);
				const newHours = (Math.floor(totalMinutes / 60) % 24);
				const newMins = (totalMinutes % 60);
				const formattedHours = String(newHours).padStart(2, "0");
				const formattedMins = String(newMins).padStart(2, "0");
				const formattedSecs = String(secs).padStart(2, "0");
				// 返回新的时间字符串
				return newdata + ` ${formattedHours}:${formattedMins}:${formattedSecs}`;
			},
			// 添加项目
			async clickAddProject() {
				const formCheck = await this.$refs.projectFormRef.checkFormData()
				if (!formCheck) return uni.$u.toast('请将表单数据填写完整')
				const duration = this.chooseProject.duration
				const startTime = this.formatDate(this.projectFormData.chooseTime).split(' ')[1]
				let [hours, minutes, seconds] = startTime.split(':').map(Number)
				const nowMinute = hours * 60 + minutes
				const endTotalMinute = nowMinute + duration
				const endHours = Math.floor(endTotalMinute / 60)
				const endMinutes = endTotalMinute % 60
				// 格式化小时和分钟
				const formattedHours = String(endHours).padStart(2, '0')
				const formattedMinutes = String(endMinutes).padStart(2, '0')

				const projectConfig = uni.$u.deepClone(this.projectConfig) //获取数据
				const waitMinute = projectConfig.find(x => x.key == "technicianId").options.find(y => y.id == this
					.chooseTechnician.id).minute //等待分钟
				console.log(projectConfig, 'waitMinute');
				const projectFormDataTime = this.formatDate(this.projectFormData.chooseTime)

				this.zyOrderItemList.unshift({
					delIndex: this.zyOrderItemList.length,
					id: this.chooseProject.id,
					itemTypeId: this.chooseProject.typeId,
					typeName: this.chooseProject.typeName,
					itemId: this.chooseProject.itemId,
					itemName: this.chooseProject.itemName,
					technicianId: this.chooseTechnician.id,
					technicianName: this.chooseTechnician.name,
					firstSelected: hours + ':' + minutes,
					lastSelected: formattedHours + ':' + formattedMinutes,
					subscribeStartTime: this.addMinutes(projectFormDataTime, waitMinute),
					// subscribeStartTime:this.projectFormData.chooseTime,
					subscribeEndTime: `${projectFormDataTime.split(' ')[0]} ${formattedHours}:${formattedMinutes}:${seconds}`,
					paymentMoney: this.chooseProject.price,
					zyOrderProductList: this.projectFormData.goods ? [{
						productId: this.chooseGoods.id,
						productName: this.chooseGoods.productName,
						originalPrice: this.chooseGoods.originalPrice
					}] : null
				})
				this.nowProjectMoney = this.$methods.numberAdd(this.nowProjectMoney, Number(this.chooseProject.price))
				if (this.chooseGoods.originalPrice) {
					this.nowGoodsMoney = this.$methods.numberAdd(this.nowGoodsMoney, Number(this.chooseGoods
						.originalPrice))
				}
				this.projectFormData = {
					...this.projectFormData,
					goods: null,
					chooseTime: null,
					technicianId: null
				}
				this.getRoomsList()
				// console.log(this.chooseProject,'this.chooseProject');
				// console.log(this.zyOrderItemList,'this.zyOrderItemList');
				// console.log(this.nowProjectMoney,'this.nowProjectMoney');
				// console.log(this.nowGoodsMoney,'this.nowGoodsMoney');
				// console.log(this.chooseGoods,'this.chooseGoods');
				// console.log(this.projectFormData,'this.projectFormData');
			},
			// 删除项目
			clickDeleteProject(item, i) {
				this.deleteDialog = true
				this.deleteItem = item
			},
			// 确认删除
			clickConfirmDelete() {
				this.zyOrderItemList = this.zyOrderItemList.filter(cItem => cItem.delIndex !== this.deleteItem.delIndex)
				this.nowProjectMoney = this.$methods.numberSub(this.nowProjectMoney, Number(this.deleteItem.paymentMoney))
				if (this.deleteItem.zyOrderProductList) {
					this.nowGoodsMoney = this.$methods.numberSub(this.nowGoodsMoney, Number(this.deleteItem
						.zyOrderProductList[0].originalPrice))
				}
				this.deleteDialog = false
			},
			getCouponList() {
				const params = {
					storeId: uni.getStorageSync('technician').belongStoreId,
					phonenumber: this.formData.phoneNumber,
					projectIds: this.zyOrderItemList.map(item => item.id),
					fullAmount: this.totalMoney
				}
				fetchCouponList(params).then(res => {
					if (res.code !== 200) return
					this.payInfoOptions.itemZyUserCouponId = res.data.map(item => {
						return {
							text: item.name,
							value: item.id
						}
					})
				})
			},
			selectChange(value, item) {
				console.log(value, item, '1111');
				if (item.key === 'itemZyUserCouponId') {
					this.chooseCoupon = value
					this.getDiscount(value)
				}
				if (item.key === 'discountType') {
					this.getDiscount(this.chooseCoupon)
					if (value == 'member') {
						this.payInfoOptions.paymentType = [{
								text: '现金',
								value: '3'
							},
							{
								text: '扫码支付',
								value: '7'
							},
							{
								text: '团购券',
								value: '8'
							}
						]
					} else if (value == 'storeCard') {
						this.payInfoOptions.paymentType = [{
							text: '余额',
							value: '5'
						}]
					} else {
						this.payInfoOptions.paymentType = [{
							text: '现金',
							value: '3'
						}, {
							text: '余额',
							value: '5'
						}, {
							text: '扫码支付',
							value: '7'
						}, {
							text: '团购券',
							value: '8'
						}]
					}
				}
				if (item.key === "paymentType" && value == 7) {
					let that = this
					uni.scanCode({
						onlyFromCamera: true,
						scanType: ['qrCode'],
						success: function(res) {
							// this.payDialog = true
							console.log('条码类型：' + res.scanType);
							console.log('条码内容：' + res.result);
							that.payCode = res.result
							console.error('this.payCode', that.payCode);
							// 处理扫描结果
						},
						fail: function(err) {
							console.error('扫描失败：', err);
							that.payCode = ''
						}
					});
				}
			},
			// 获取会员和储值折扣价
			getDiscount(value) {
				const zyOrderProductList = []
				const zyOrderItemList = this.zyOrderItemList.map(item => {
					if (item.zyOrderProductList) {
						zyOrderProductList.push(...item.zyOrderProductList)
					}
					return {
						itemId: item.itemId,
						technicianId: item.technicianId,
						subscribeStartTimeString: item.subscribeStartTime,
						paymentMoney: item.paymentMoney
					}
				})
				const params = {
					phoneNumber: this.formData.phoneNumber,
					regionId: uni.getStorageSync('technician').belongAreaId,
					regionName: uni.getStorageSync('technician').belongAreaName,
					storeId: uni.getStorageSync('technician').belongStoreId,
					storeName: uni.getStorageSync('technician').belongStoreName,
					isMember: this.payInfoData.discountType === 'storeCard' ? '2' : '1',
					compartmentId: this.chooseRoom.id,
					compartmentName: this.chooseRoom.compartmentName,
					compartmentMoney: this.roomMoney,
					isValue: this.payInfoData.discountType === 'storeCard' ? '1' : '2',
					useInterestsType: 0,
					itemCoupon: value || null,
					zyOrderItemList,
					zyOrderProductList
				}
				fetchCouponDiscount(params).then(res => {
					if (res.code !== 200) return
					this.couponDiscount = res.data.discount || 0
				})
			},
			// 确定
			async clickSubmit(payMethod) {
				this.payMethod = payMethod
				const userFormCheck = await this.$refs.userFormRef.checkFormData()
				if (!userFormCheck) return uni.$u.toast('请将表单数据填写完整')
				if (!this.zyOrderItemList.length) return uni.$u.toast('请选择服务项目')
				this.payInfoData = {
					phoneNumber: this.formData.phoneNumber,
					userName: this.formData.userName,
					valueMoney: this.formData.valueMoney,
					memberFlag: this.formData.memberFlag === '1' ? '是' : '否',
					orderAmount: this.totalMoney
				}
				if (payMethod == 'payNow') {
					this.getCouponList()
					this.payInfoDialog = true
				} else {
					this.clickSubmitPay()
				}

			},
			// 确定开单
			clickSubmitPay() {
				this.SubmitParams = {
					ifApp: true,
					regionId: uni.getStorageSync('technician').belongAreaId,
					regionName: uni.getStorageSync('technician').belongAreaName,
					storeId: uni.getStorageSync('technician').belongStoreId,
					storeName: uni.getStorageSync('technician').belongStoreName,
					phoneNumber: this.formData.phoneNumber,
					userName: this.formData.userName,
					isMember: this.payInfoData.discountType === 'member' ? '1' : '2',
					// payCode: this.payInfoData.paymentType === '7' ? this.payCode : null,
					isPayNow: this.payMethod === 'payNow' ? 1 : null,
					compartmentId: this.chooseRoom.id,
					compartmentName: this.chooseRoom.compartmentName,
					compartmentMoney: this.roomMoney,
					isValue: this.payInfoData.discountType === 'storeCard' ? '1' : '2',
					paymentType: this.payInfoData.paymentType,
					itemMoney: this.allProjectMoney, // 项目金额
					actuallyMoney: this.actuallyMoney, // 实付金额
					discountsMoney: this.discountsMoney,
					itemZyUserCouponId: this.payInfoData.itemZyUserCouponId,
					zyOrderItemList: uni.$u.deepClone(this.zyOrderItemList)
				}
				addOrder(this.SubmitParams).then(res => {
					if (res.code !== 200) return
					this.orderId = res.data.orderId
					this.payInfoDialog = false
					if (this.payMethod === 'payNow') {
						console.log('立即支付？？？？？');
						this.clickSurePay()
					} else {
						uni.$u.toast('下单完成')
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/index'
							})
						}, 1500)

					}
				})
			},
			// 确定支付
			clickSurePay() {
				let params = {
					// id: this.orderId,
					paymentType: this.payInfoData.paymentType,
					...this.SubmitParams
				}
				if (this.payInfoData.paymentType === '8') {
					params = {
						...params,
						groupPurchaseId: this.payInfoData.groupPurchaseId,
						groupPurchaseMoney: this.payInfoData.groupPurchaseMoney,
					}
				}
				if (this.payInfoData.paymentType === '7') {
					params = {
						...params,
						payCode: this.payCode
					}
				}
				orderPay(params).then(res => {
					if (res.code !== 200) return uni.$u.toast(res.msg)
					uni.redirectTo({
						url: '/subPages/order/payResult?payResult=success'
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn-box {
		width: 100%;
		display: flex;
		justify-content: flex-end;
		padding-top: 30rpx;

		.add-btn {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 300rpx;
			height: 80rpx;
			border-radius: 40rpx;
			font-size: 32rpx;
			color: #FFF;
			background-color: #c17e13;
		}
	}

	.project-list {
		margin: 20rpx 0;
		padding: 10rpx 30rpx 30rpx;
		border-radius: 16rpx;
		background-color: #eaeaea;

		.common-item {
			display: flex;
			justify-content: space-between;
			padding: 20rpx 0;

			.item {
				font-size: 32rpx;
			}
		}

		.delete-box {
			display: flex;
			justify-content: flex-end;

			.delete-btn {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 150rpx;
				height: 60rpx;
				border-radius: 30rpx;
				font-size: 32rpx;
				color: #FFF;
				background-color: #e93031;
			}
		}
	}

	.fee-detail {
		margin: 30rpx;
		padding: 30rpx 40rpx;
		border-radius: 18rpx;
		background-color: #FFF;

		.fee-title {
			font-size: 32rpx;
			font-weight: 600;
		}

		.fee-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 110rpx;
			border-bottom: 2rpx solid #eee;

			&:last-child {
				border-bottom: none;
			}

			.fee-label {
				flex: 1;
				font-size: 30rpx;
				font-weight: 500;
				color: #000;
			}
		}

		.btn-box {
			display: flex;
			justify-content: space-around;
			align-items: center;

			.confirm-btn {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 45%;
				height: 80rpx;
				margin: 30rpx 0 1rpx;
				border-radius: 40rpx;
				font-size: 32rpx;
				color: #FFF;
				background-color: #c17e13;
			}
		}
	}

	::v-deep.pay-info-box {
		padding: 30rpx 40rpx;

		.pay-info-item {
			display: flex;
			align-items: center;
			margin: 20rpx 0;

			.item-select-label {
				width: 150rpx;
			}

			.item-value,
			.item-select {
				flex: 1;

				.select {
					width: 100%;
				}

				.uni-select {
					height: 60rpx !important;
				}
			}
		}

		.pay-btn {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 80rpx;
			margin: 40rpx 0 1rpx;
			border-radius: 40rpx;
			font-size: 32rpx;
			color: #FFF;
			background-color: #c17e13;
		}

		.is-input-border {
			margin-bottom: 20rpx;
			border: none;
			border-radius: 35rpx;
			text-align: center;
			font-size: 28rpx;
			background-color: #f2f2f2 !important;
		}

		.uni-input-placeholder {
			font-size: 28rpx;
			color: #6e6e6e;
		}

		.item-selected {
			background-color: #fff6e7 !important;
		}
	}

	.delete-box {
		padding: 0 0 30rpx;

		.delete-text {
			margin-bottom: 30rpx;
			font-size: 34rpx;
			text-align: center;
		}

		.delete-btn {
			display: flex;
			justify-content: center;
			align-items: center;

			.btn-item {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 160rpx;
				height: 70rpx;
				margin: 0 10rpx;
				border-radius: 35rpx;
				font-size: 32rpx;
				color: #FFF;
				background-color: #c17e13;
			}

			.cancel-item {
				color: #c17e13;
				background-color: #f5f5f5;
			}
		}
	}

	.pay-box {
		padding: 30rpx 0;

		.pay-item {
			text-align: center;
			margin-bottom: 20rpx;
			font-size: 32rpx;
			font-weight: 500;
		}

		.confirm-pay-btn {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 80%;
			height: 70rpx;
			margin: 10rpx auto;
			border-radius: 35rpx;
			font-size: 28rpx;
			color: #FFF;
			background-color: #c17e13;
		}
	}
</style>